package com.zeng.conditional;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @author Zqm
 * @Title: LinuxConditional
 * @ProjectName SpringAnnotationDriven
 * @date 2019/1/11
 */
public class LinuxConditional implements Condition {


    @Override
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
        //获取ioc beanFactory
        ConfigurableListableBeanFactory beanFactory = conditionContext.getBeanFactory();

        //获取类加载器
        ClassLoader classLoader = conditionContext.getClassLoader();

        //获取环境
        Environment environment = conditionContext.getEnvironment();

        //回去bean 定义的注册类
        BeanDefinitionRegistry registry = conditionContext.getRegistry();

        String property = environment.getProperty("os.name");
        if (property.contains("linux")){
            return true;
        }
        return false;
    }
}
